#include<iostream>
#include<cmath>
using namespace std;
int t,n,a[200001],f[200001],ans;
void dfs(int x){
    if(x==n+1){
            int s=0;
        for(int i=2;i<=n;i++){
            int j=i-1;
            while(f[j]!=f[i]&&j>=1)
                j--;
            if(a[i]==a[j])
                s+=a[i];
        }
        ans=max(s,ans);
        return;
    }
    while(a[x]==a[x-1]){
        f[x]=f[x-1];
        x++;
    }
        f[x]=1;
        dfs(x+1);
        f[x]=2;
        dfs(x+1);
    return;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
            ans=0;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        f[1]=1;
        dfs(2);
        cout<<ans<<endl;
    }
return 0;
}
